<?php
use Mini\App;
use Mini\AsyncHttpClient;

const BASE_PATH = __DIR__;
// 配置
$config = require BASE_PATH . '/config/app.php';
// 时区设置
date_default_timezone_set($config['timezone']);
require_once BASE_PATH . '/vendor/autoload.php';



$client = new AsyncHttpClient();

$urls = [
    'http://192.168.3.243:8000/my?id=1',
    'http://192.168.3.243:8000/my?id=2',
];

$start = microtime(true);

try {
    foreach ($urls as $url) {
        $client->get($url)
            ->then(function ($response) {
                echo "成功: \n$response\n";
            })
            ->catch(function ($error) {
                echo "失败: {$error->getMessage()}\n";
            });
    }
    $client->run();
} catch (\Throwable $e) {
    var_dump($e->getMessage());
}

$end = microtime(true);

echo "总耗时: " . ($end - $start) . " 秒\n";
App::loop()->run();
$end = microtime(true);

echo "总耗时: " . ($end - $start) . " 秒\n";